<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\home\models\ArticleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '文章管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="article-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('创建文章', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\ActionColumn'],

            [
                'attribute' => 'id',
                'value' => 'id',
                'headerOptions' => ['width' => '50'],
            ],
            [
                'format' => 'raw',
                'attribute' => 'type',
                'value' => function($model) {
                    if($model->type == 0){
                        return '<span class="btn btn-xs btn-info">单页面</span>';
                    } else {
                        return '<span class="btn btn-xs btn-info">论文资源</span>';
                    }
                },
                'filter' => ['0' => '单页面', '1' => '论文资源'],
            ],
            'cid',
            'title',
            // 'summary',
            //'author',
            //'read',
            //'is_hot',
            //'is_recommend',
            //'tag',
            //'order',
            //'image_path',
            //'url:url',
            //'content:ntext',
            [
                'format' => 'raw',
                'attribute' => 'status',
                'value' => function($model) {
                    if($model->status == 0){
                        return '<span class="btn btn-xs btn-danger">未发布</span>';
                    } elseif ($model->status == 1) {
                       return '<span class="btn btn-xs btn-success">已发布</span>';
                    } else {
                        return '';
                    }

                },
                'filter' => ['0' => '未发布', '1' => '已发布'],
            ],
            'publish_date',
            //'create_time',

            
        ],
    ]); ?>
</div>
